CSharpTest.Net
Create Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Interfaces Namespace > IFactory<T> Interface : Create Method

Glossary Item Box

Creates an instance of an object assignable to type T

Syntax

Visual Basic (Declaration) 
Function Create() As T
C# 
T Create()

Example

Library/Library.Test/TestStreamCache.cs

C#Copy Code
Stream stream;
using (StreamCache cache = new StreamCache(new SharedMemoryStream(), 1))
{
    using (stream = cache.Open())
    {
        Assert.IsTrue(stream.CanRead);
        Assert.IsTrue(stream.CanWrite);
        Assert.IsTrue(stream.CanSeek);
    }
    using (stream = ((IFactory<Stream>)cache).Create())
    {
        Assert.IsTrue(stream.CanRead);
        Assert.IsTrue(stream.CanWrite);
        Assert.IsTrue(stream.CanSeek);
    }
    using (stream = cache.Open(FileAccess.Read))
    {
        Assert.IsTrue(stream.CanRead);
        Assert.IsFalse(stream.CanWrite);
        Assert.IsTrue(stream.CanSeek);
    }
    using (stream = cache.Open(FileAccess.Write))
    {
        Assert.IsFalse(stream.CanRead);
        Assert.IsTrue(stream.CanWrite);
        Assert.IsTrue(stream.CanSeek);
    }
}
VB.NETCopy Code
Dim stream As Stream
Using cache As New StreamCache(New SharedMemoryStream(), 1)
    Using stream = cache.Open()
        Assert.IsTrue(stream.CanRead)
        Assert.IsTrue(stream.CanWrite)
        Assert.IsTrue(stream.CanSeek)
    End Using
    Using stream = (DirectCast(cache, IFactory(Of Stream))).Create()
        Assert.IsTrue(stream.CanRead)
        Assert.IsTrue(stream.CanWrite)
        Assert.IsTrue(stream.CanSeek)
    End Using
    Using stream = cache.Open(FileAccess.Read)
        Assert.IsTrue(stream.CanRead)
        Assert.IsFalse(stream.CanWrite)
        Assert.IsTrue(stream.CanSeek)
    End Using
    Using stream = cache.Open(FileAccess.Write)
        Assert.IsFalse(stream.CanRead)
        Assert.IsTrue(stream.CanWrite)
        Assert.IsTrue(stream.CanSeek)
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Reference

IFactory<T> Interface
IFactory<T> Members

Used By

TestCollection.TestAddRemove()
TestCollection.TestAddReverseRemove()
TestCollection.TestClear()
TestCollection.TestContains()
TestCollection.TestCopyTo()
TestCollection.TestIsReadOnly()
TestCollection.TestGetEnumerator()
TestCollection.TestGetEnumerator2()
TestDictionary.TestAddRemoveByKey()
TestDictionary.TestKeys()
TestDictionary.TestValues()
Stream StreamCache.Open(FileAccess)
ILockStrategy LockCounterFactory.Create()

Source Code

Library/Interfaces/IFactory.cs

Generated with Document! X 2011 by Innovasys